package com.baibei.ebec.follow.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.RaeTabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.baibei.ebec.follow.fragment.MyFansFragment;
import com.baibei.ebec.follow.fragment.MyFollowFragment;
import com.baibei.ebec.home.R;
import com.baibei.ebec.home.R2;
import com.baibei.module.AppRouter;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = AppRouter.ROUTE_MY_FOLLOW)
public class MyFollowActivity extends AppCompatActivity {

    @BindView(R2.id.tab_layout)
    RaeTabLayout tabLayout;
    @BindView(R2.id.view_pager)
    ViewPager viewPager;
    private String[] titles;
    private ArrayList<Fragment> fragments;
    private FragmentAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_follow);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        titles = new String[]{"我关注的大神", "谁跟我买"};
        fragments = new ArrayList<>();
        fragments.add(new MyFollowFragment());
        fragments.add(new MyFansFragment());
        adapter = new FragmentAdapter(getSupportFragmentManager());
        viewPager.setOffscreenPageLimit(fragments.size());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    @OnClick(R2.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @OnClick(R2.id.iv_xiaoxi)
    public void onMsgClicked() {
        AppRouter.routeToMessage(this);
    }

    public class FragmentAdapter extends FragmentPagerAdapter {
        public FragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return fragments.get(i);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }
}
